# Maintainer: Alexey Pavlov <alexpux@gmail.com>
# Contributor: Ray Donnelly <mingw.android@gmail.com>

_realname=gegl
pkgbase="mingw-w64-${_realname}"
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=0.4.40
pkgrel=4
pkgdesc="Generic Graphics Library (mingw-w64)"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clang32' 'clangarm64')
url="https://gegl.org/"
license=('spdx:GPL-3.0-or-later' 'spdx:LGPL-3.0-or-later')
makedepends=("${MINGW_PACKAGE_PREFIX}-asciidoc"
             "${MINGW_PACKAGE_PREFIX}-cc"
             "${MINGW_PACKAGE_PREFIX}-gobject-introspection"
             "${MINGW_PACKAGE_PREFIX}-gtk-doc"
             $([[ ${MSYSTEM_CARCH} == aarch64 ]] || echo "${MINGW_PACKAGE_PREFIX}-luajit")
             "${MINGW_PACKAGE_PREFIX}-pkgconf"
             "${MINGW_PACKAGE_PREFIX}-vala"
             "${MINGW_PACKAGE_PREFIX}-meson")
depends=("${MINGW_PACKAGE_PREFIX}-babl"
         "${MINGW_PACKAGE_PREFIX}-cairo"
         "${MINGW_PACKAGE_PREFIX}-exiv2"
         "${MINGW_PACKAGE_PREFIX}-ffmpeg"
         "${MINGW_PACKAGE_PREFIX}-gexiv2"
         "${MINGW_PACKAGE_PREFIX}-gcc-libs"
         "${MINGW_PACKAGE_PREFIX}-gdk-pixbuf2"
         "${MINGW_PACKAGE_PREFIX}-gettext"
         "${MINGW_PACKAGE_PREFIX}-glib2"
         "${MINGW_PACKAGE_PREFIX}-jasper"
         "${MINGW_PACKAGE_PREFIX}-json-glib"
         "${MINGW_PACKAGE_PREFIX}-libjpeg"
         "${MINGW_PACKAGE_PREFIX}-libpng"
         "${MINGW_PACKAGE_PREFIX}-libraw"
         "${MINGW_PACKAGE_PREFIX}-librsvg"
         "${MINGW_PACKAGE_PREFIX}-libspiro"
         "${MINGW_PACKAGE_PREFIX}-libwebp"
         "${MINGW_PACKAGE_PREFIX}-lcms"
         "${MINGW_PACKAGE_PREFIX}-lensfun"
         "${MINGW_PACKAGE_PREFIX}-maxflow"
         "${MINGW_PACKAGE_PREFIX}-omp"
         "${MINGW_PACKAGE_PREFIX}-openexr"
         "${MINGW_PACKAGE_PREFIX}-pango"
         "${MINGW_PACKAGE_PREFIX}-poppler"
         "${MINGW_PACKAGE_PREFIX}-SDL2"
         "${MINGW_PACKAGE_PREFIX}-suitesparse")
#options=('!strip' 'debug')
noextract=("${_realname}-${pkgver}.tar.xz")
source=(https://download.gimp.org/pub/gegl/${pkgver%.*}/${_realname}-${pkgver}.tar.xz
        "https://gitlab.gnome.org/GNOME/gegl/-/merge_requests/133.patch")
sha256sums=('cdde80d15a49dab9a614ef98f804c8ce6e4cfe1339a3c240c34f3fb45436b85d'
            '61ab741b720546e8812b5d8d523a3766d47778414f734960080aca3a13598da4')

apply_patch_with_msg() {
  for _patch in "$@"
  do
    msg2 "Applying ${_patch}"
    patch -Nbp1 -i "${srcdir}/${_patch}"
  done
}

prepare() {
  tar -xf "${_realname}-${pkgver}.tar.xz" || true
  tar -xf "${_realname}-${pkgver}.tar.xz" || true
  cd "${_realname}-${pkgver}"

  apply_patch_with_msg 133.patch
}

build() {
  [[ -d build-${MSYSTEM} ]] && rm -rf build-${MSYSTEM}
  mkdir -p build-${MSYSTEM} && cd build-${MSYSTEM}

# FIXME: re-enable docs after this issue is fixed:
# https://gitlab.gnome.org/GNOME/gegl/-/issues/294

  MSYS2_ARG_CONV_EXCL="--prefix=" \
  ${MINGW_PREFIX}/bin/meson.exe \
    --prefix="${MINGW_PREFIX}" \
    --buildtype=plain \
    --auto-features=enabled \
    -Dlibv4l=disabled \
    -Dlibv4l2=disabled \
    -Dmrg=disabled \
    -Dpygobject=disabled \
    -Dsdl1=disabled \
    -Dintrospection=true \
    -Ddocs=false \
    $([[ ${MSYSTEM_CARCH} == aarch64 ]] && echo "-Dlua=disabled") \
    ../${_realname}-${pkgver}

  ${MINGW_PREFIX}/bin/meson.exe compile
}

package() {
  cd build-${MSYSTEM}
  DESTDIR="${pkgdir}" ${MINGW_PREFIX}/bin/meson.exe install

  rm "${pkgdir}${MINGW_PREFIX}"/lib/gegl-*/*.dll.a
}
